package br.com.sis.rh.facade;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import br.com.sis.rh.dao.AlocacaoDAO;
import br.com.sis.rh.dao.CandidatoDAO;
import br.com.sis.rh.entity.Alocacao;
import br.com.sis.rh.entity.Candidato;

@Service
@Transactional
public class AlocacaoFacadeImpl extends GenericFacadeImpl<Alocacao, AlocacaoDAO> implements AlocacaoFacade {

	public AlocacaoFacadeImpl() {
		super(AlocacaoDAO.class);
	}

	@Autowired
	private CandidatoDAO candidatoDAO;
	
	@Autowired
	private AlocacaoDAO alocacaoDAO;
	
	@Override
	public void excluir(Alocacao objeto) {
		Alocacao alocacao = alocacaoDAO.recuperarObjetoPorID(objeto);
		Candidato candidato = candidatoDAO.recuperarObjetoPorID(alocacao.getCandidato());
		
		candidato.getAlocacao().remove(alocacao);
		
		candidatoDAO.alterar(candidato);
	}
}
